import React from 'react';
import { Input, Button, Select, Upload, Form, Cascader, DatePicker, Row, Col, Modal, message, Icon, Card, Pagination } from 'antd';
import './registerTriage.less';
import { browserHistory } from 'react-router';
import region from '../../common/region';
import getFormatDate from '../../common/getFormatData';
import config from '../../config/config';
import $ from 'jquery';
const allRouter = config.router;
const nations = config.nationData;
const FormItem = Form.Item;
const Search = Input.Search;
const Option = Select.Option;
const InputGroup = Input.Group;
const { RangePicker } = DatePicker;
const token = sessionStorage.getItem('token');
let userInfo = JSON.parse(sessionStorage.getItem('UserInfo')); //用户信息
let allTimePhase = ['00:00~00:30', '00:30~01:00', '01:00~01:30', '01:30~02:00', '02:00~02:30', '02:30~03:00', '03:00~03:30', '03:30~04:00', '04:00~04:30', '04:30~05:00', '05:00~05:30', '05:30~06:00', '06:00~06:30', '06:30~07:00', '07:00~07:30', '07:30~08:00', '08:00~08:30', '08:30~09:00', '09:00~09:30', '09:30~10:00', '10:00~10:30', '10:30~11:00', '11:00~11:30', '11:30~12:00', '12:00~12:30', '12:30~13:00', '13:00~13:30', '13:30~14:00', '14:00~14:30', '14:30~15:00', '15:00~15:30', '15:30~16:00', '16:00~16:30', '16:30~17:00', '17:00~17:30', '17:30~18:00', '18:00~18:30', '18:30~19:00', '19:00~19:30', '19:30~20:00', '20:00~20:30', '20:30~21:00', '21:00~21:30', '21:30~22:00', '22:00~22:30', '22:30~23:00', '23:00~23:30', '23:30~24:00'];
let allTimeIndex = ['00:00', '00:30', '01:00', '01:30', '02:00', '02:30', '03:00', '03:30', '04:00', '04:30', '05:00', '05:30', '06:00', '06:30', '07:00', '07:30', '08:00', '08:30', '09:00', '09:30', '10:00', '10:30', '11:00', '11:30', '12:00', '12:30', '13:00', '13:30', '14:00', '14:30', '15:00', '15:30', '16:00', '16:30', '17:00', '17:30', '18:00', '18:30', '19:00', '19:30', '20:00', '20:30', '21:00', '21:30', '22:00', '22:30', '23:00', '23:30'];
let uuid = 0;
let descCount = 0;
class LoginTriage extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            tabKey: 1,//当前显示的页面内容 1新增患者 2登记记录
            visible: false,//选择医生模态框
            visible1: false,//点击医生头像，确认分诊医生信息
            visible2: false,//重新预约模态框
            visible3: false,//重新预约确认模态框
            fileList: [],//上传图片列表
            age: 0,//计算年龄
            patientOriginList: [],//患者来源列表
            userTypeManageList: [],//会员类型
            registrationFeeList: [],//挂号费医生展示列表
            allList: [],//所有挂号费医生列表
            allList1: [],//所有挂号费医生列表  //test
            departmentsList: [],//科室列表,模态框展示
            storeInfo: [],//门店信息
            limitNum: 0,//每个医生每个时间段最多接诊多少人
            patientInfo: '',//此患者信息，在保存后，分诊需要用到
            patientInfos: { data: [] },//所有患者信息
            date: [], // 时间
            data1: [],//时间字符串
            allTimePhase: [],//选择医生时候模态框的时间段数组，根据门店设置的起止时间变化
            everyDoctorList: [],//选择医生时候模态框的医生筛选数组
            selectedDepartment: '',//记录是否有选择科室，筛选时为且关系
            selectedDoctor: '',//记录是否有选择医生，筛选时为且关系
            selectedTimePhase: '',//记录是否有选择时间段，筛选时为且关系
            departmentValue: '',//记录模态框已经选中的值，主要是为了取消模态框后再打开模态框select还有值  科室
            DoctorValue: '',//记录模态框已经选中的值，主要是为了取消模态框后再打开模态框select还有值   医生
            timePhaseValue: '',// 记录模态框已经选中的值，主要是为了取消模态框后再打开模态框select还有值 时间段
            DoctorScheduleList: [],//医生排班列表
            schedulingsList: [],//班次列表   总设置
            thisDoctorInfo: {},//点击模态框医生头像显示医生详情
            Inkey: '',// 关键字
            pagesize: 12,// 每页显示的页数
            pageindex: 1,// 当前页
            discount: 1,//根据会员等级的挂号费打折
            isHavingId: false,//是否是先登记完成以后再分诊
            registedId: '',//已经登记的患者再分诊的id
            everyDoctorList1:[],//所有医生数据
            isAlreadyChosedIdCard:false,//是否选择了证件类型，决定ID号码是否填写
        }
    }
    componentWillMount() {
        userInfo = JSON.parse(sessionStorage.getItem('UserInfo')); //用户信息
        this.getScheduleList();
        // const start = new Date().toISOString().slice(0, 10);
        // console.log(start);
        this.setState({
            data1: ['', '']
        })
        // this.getDoctorTestList();
    }
    componentDidMount() {
        if (this.props.location.state) {
            console.log(this.props.location.state);
            this.changeTab(2);
        }
        //处理省市区数据
        this.handleRegion();
        //获取患者来源列表
        this.getOriginPatientList();
        //获取会员类型列表
        this.getUsersList();
    }
    //获取患者来源列表
    getOriginPatientList() {
        let url = allRouter.patientOrigin + '/source/list';
        //console.log(url);
        $.ajax({
            url: url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
            success: data => {
                console.log(data);
                if (data.code === 200) {
                    //对禁用的数据进行过滤
                    this.setState({
                        patientOriginList: data.sources.filter(key => key.state !== '禁用')
                    }, () => {
                        console.log(this.state.patientOriginList);
                    })
                } else {
                    console.log("获取患者来源列表出错");
                }
            },
            error: err => {
                console.log(err);
            }
        });
    }
    //获取会员类型列表
    getUsersList() {
        let url = allRouter.patientOrigin + '/grade/list';
        //console.log(url);
        $.ajax({
            url: url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
            success: data => {
                this.setState({
                    userTypeManageListCount: data.gread.length
                });
                if (data.code === 200) {
                    this.setState({ userTypeManageList: data.gread.filter(key => key.state !== '禁用') }, () => {
                        console.log(this.state.userTypeManageList);
                    })
                } else {
                    console.log("获取会员类型列表出错");
                }
            },
            error: err => {
                console.log(err);
            }
        });
    }
    //获取科室列表
    getDepartmentsList() {
        let url = allRouter.patientOrigin + '/department/list';
        //console.log(url);
        $.ajax({
            url:url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer '+sessionStorage.getItem('token')},
            success:data=>{
                console.log(data);
                if (data.code === 200) {
                    //给列表每一项增加索引
                    this.setState({
                        departmentsList: data.department.filter(key => key.state !== '禁用'),
                    }, () => {
                        console.log(this.state.departmentsList);
                    })
                } else {
                    console.log("获取科室列表列表出错");
                }
            },
            error:err=>{
                console.log(err);
            }
        });
    }
     //获取医生列表
     getDoctorList(){
        let url=allRouter.patientOrigin+'/doctor/list';
        $.ajax({
            url:url,
            type: "get",
            async: true,
            headers: { Authorization: 'Bearer '+sessionStorage.getItem('token')},
            success:data=>{
                console.log(data);
                if(data.code===200){
                    this.setState({
                        // everyDoctorList:data.users.filter(key=>key.department.filter(key=>key!=null).length>0&&key.role==='医生'&&key.state!=='禁用'),
                        everyDoctorList1:data.users.filter(key=>key.department.filter(key=>key!=null).length>0&&key.role==='医生'&&key.state!=='禁用'),
                        
                    },()=>{
                        console.log('everyDoctorList');
                        console.log(this.state.everyDoctorList);
                        
                    })
                }else{
                    console.log("获取员工列表出错");
                }
            },
            error:err=>{
                console.log(err);
            }
        })
    }
    //获取总的医生排班列表
    getDoctorScheduleList(timePhase,department,doctorname) {
        console.log('timePhase');
        console.log(timePhase);
        let url = allRouter.patientOrigin + '/doctor/savePatient';
        $.ajax({
            url: url,
            type: "POST",
            async: true,
            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
            data: {
                starttime: new Date().toLocaleDateString(),
                endtime: new Date().toLocaleDateString(),
                time: timePhase.slice(6, 11),
                department,
                doctorname,
            },
            success: data1 => {
                console.log("医生排班列表:");
                console.log(data1);
                if (data1.code === 200) {
                    //获取挂号费列表
                    let url = allRouter.patientOrigin + '/registration/list';
                    $.ajax({
                        url: url,
                        type: "get",
                        async: true,
                        headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
                        success: data => {
                            console.log('医生挂号费列表:');
                            console.log(data);
                            if (data.code === 200) {
                                data.data=data.data.filter(key => key.state !== '禁用');
                                data1.data.map(item1=>{
                                    data.data.map(item=>{
                                        if(item1.id===item.doctorid){
                                            item1.price=item.price;
                                            item1.level=item.level;
                                        }
                                    })
                                });
                                this.setState({
                                    registrationFeeList: this.state.limitNum===0?data1.data:data1.data.filter(key=>(key.totreat?key.totreat:0)<this.state.limitNum),
                                },()=>{
                                    console.log('列表大幅度方法');
                                    console.log(this.state.registrationFeeList);
                                })
                            } else {
                                console.log("获取医生挂号费列表出错");
                            }
                        },
                        error: err => {
                            console.log(err);
                        }
                    })
                } else {
                    this.setState({
                        registrationFeeList: [],
                    },()=>{
                    });
                    console.log("获取医生排班列表出错");
                }
            },
            error: err => {
                console.log(err);
            }
        })
    }
    //获取班次列表
    getScheduleList() {
        let url = allRouter.patientOrigin + '/sheduling/list';
        console.log(url);
        $.ajax({
            url: url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
            success: data => {
                console.log(data);
                if (data.code === 200) {
                    this.setState({
                        schedulingsList: data.schedulings.filter(key => key.state !== '禁用')
                    }, () => {
                        console.log('schedulingsList');
                        console.log(this.state.schedulingsList);
                    })
                } else {
                    console.log("获取班次列表出错");
                }
            },
            error: err => {
                console.log(err);
            }
        });
    }
    //处理省市区数据
    handleRegion() {
        const setOptions = arr => {
            arr.map((item, key) => {
                item.value = item.name;
                item.label = item.name;
                if (item.child) {
                    item.children = item.child;
                    setOptions(item.children);
                }
            });
        };
        setOptions(region);
        this.setState({
            region
        });
    }
    //禁用今天以后的日期
    disabledDate(val) {
        if (val) {
            return val.valueOf() > Date.now();
        } else {
            return false;
        }
        //return current.valueOf() > Date.now();
    }
    //限制用户必须上传图片格式的文件、图片大小
    beforeUpload(file, fileList) {
        let isIMG = file.type.indexOf('image') != -1;
        if (!isIMG) {
            message.config({ top: 50 });
            message.error('您只能上传图片！');
        }
        let isLt10M = file.size / 1024 / 1024 < 10;
        if (!isLt10M) {
            message.config({ top: 50 });
            message.error('您上传的图片大小必须小于10MB！');
        }
        return isIMG && isLt10M;
    }
    //预览图片对话框
    previewImg(file) {
        this.setState({
            previewImage: file.url || file.thumbUrl,
            previewVisible: true,
        });
    }
    //上传图片
    normFile(e) {
        this.setState({
            fileList: e.fileList
        });
        if (Array.isArray(e)) {
            return e;
        }
        return e && e.fileList;
    }
    //关闭预览图片对话框
    cancelPreview() {
        this.setState({ previewVisible: false })
    }
    //改变tab页面 切换登记记录与新增患者页面内容
    changeTab(key) {
        const start = getFormatDate(new Date());
        console.log(start);
        this.setState({ tabKey: key });
        if (key === 2) {
            if (this.props.location.state) {
                this.getPatientInfo(1, '', '', this.props.location.state);
            } else {
                this.setState({
                    date:[undefined,undefined],
                    data1: ['',''],
                    Inkey: undefined,
                });
                this.getPatientInfo(1,);
            }
        }
    }
    //选择日期，计算年龄
    calculateAge(date) {
        if (date) {
            let bornYear = date.format('YYYY');
            let currentYear = new Date().getFullYear();
            this.setState({
                age: currentYear - bornYear
            })
        } else {
            this.setState({
                age: 0,
            })
        }
    }
    //移除家庭成员
    remove(k) {
        const { form } = this.props;
        const keys = form.getFieldValue('keys');
        if (keys.length === 0) {
            return;
        }
        descCount++;
        form.setFieldsValue({
            keys: keys.filter(key => key !== k),
        });
    }
    //增加家庭成员
    add() {
        const { form } = this.props;
        const keys = form.getFieldValue('keys');
        const nextKeys = keys.concat(uuid);
        console.log(nextKeys);
        uuid++;
        form.setFieldsValue({
            keys: nextKeys,
        });
    }
    //分诊选择医生模态框中选择 科室 筛选
    handleChangeDepartment(value) {
        this.setState({
            selectedDepartment: value,
            departmentValue: value,
            selectedDoctor: undefined,
            doctorValue: undefined,
        });
        this.getDoctorScheduleList(this.state.timePhaseValue,value);
        let arr=[];
        this.state.everyDoctorList1.map(item=>{
            if(item.department){
                if(item.department.length){
                    if(item.department[0]._id===value){
                        arr.push(item);
                    }
                }
            }
        })
        this.setState({
            everyDoctorList:arr,
        })
        
    }
    //分诊选择医生模态框中选择 医生 筛选
    handleChangeDoctor(value) {
        this.setState({
            selectedDoctor: value,
            doctorValue: value,
        });
        this.getDoctorScheduleList(this.state.timePhaseValue,this.state.departmentValue,value)
    }
    //分诊选择医生模态框中选择 时间段 筛选
    handleChangeTimePhase(value) {
        this.setState({
            selectedTimePhase: value,
            timePhaseValue: value,
        });
        this.getDoctorScheduleList(value,this.state.departmentValue,this.state.doctorValue)


    }
    //获取患者登记信息
    getPatientInfo(pageindex, starttime, endtime, value) {
        if (this.props.location.state) {
            starttime = '';
            endtime = '';
            value = this.props.location.state;
        }
        let url = allRouter.patientOrigin + '/patient/list';
        $.ajax({
            url: url,
            type: "post",
            async: true,
            traditional: true,
            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
            data: {
                pageindex,
                pagesize: 12,
                starttime,
                endtime,
                searchtext: value,
            },
            success: data => {
                if(data.code===200){
                    data.data=data.data.reverse();
                    this.setState({
                        patientInfos: data,
                    }, () => {
                        console.log('患者信息 list');
                        console.log(this.state.patientInfos);
                    })
                }
            },
            error: err => {
                console.log(err);
            }
        });
    }
    //获取门店信息
    getStoreInfo(storeId) {
        let url = allRouter.patientOrigin + '/cmmuseum/one/' + storeId;
        $.ajax({
            url: url,
            type: "GET",
            async: true,
            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
            success: data => {
                console.log(data);
                if (data.code === 200) {
                    this.setState({
                        storeInfo: data.cmmuseum,
                        limitNum: data.cmmuseum.limitnumber
                    }, () => {
                        console.log('门店信息');
                        console.log(this.state.storeInfo);
                        let startTime = this.state.storeInfo.starttime.slice(0, 5);
                        let endTime = this.state.storeInfo.endtime.slice(0, 5);
                        let startIndex = allTimeIndex.indexOf(startTime);
                        let endIndex = allTimeIndex.indexOf(endTime);
                        // console.log(startIndex);
                        // console.log(endIndex);
                        const timeHourMinute = new Date().toTimeString().slice(0, 5);
                        // console.log(timeHourMinute);
                        let index = 0;
                        for (let i = 0; i < allTimeIndex.length; i++) {
                            if (timeHourMinute >= allTimeIndex[i] && timeHourMinute <= allTimeIndex[i + 1]) {
                                index = i;
                                break;
                            }
                        }
                        if(index>endIndex||index<startIndex){
                            this.setState({
                                allTimePhase: []
                            }, () => {
                                console.log(this.state.allTimePhase);
                            })
                        }else{
                            this.setState({
                                allTimePhase: (allTimePhase.slice(index, endIndex))
                            }, () => {
                                console.log(this.state.allTimePhase);
                            })
                        }
                    })
                } else {
                    console.log("获取门店信息出错");
                }
            },
            error: err => {
                console.log(err);
            }
        });
    }
    //完成登记并分诊
    saveAndTriage() {
        //获得当前时间段
        this.props.form.validateFields((err, fieldsValue) => {
            console.log(err, fieldsValue);
            if (!err) {
                const timeHourMinute = new Date().toTimeString().slice(0, 5);
                // console.log(timeHourMinute);
                let index = 0;
                for (let i = 0; i < allTimeIndex.length; i++) {
                    if (timeHourMinute >= allTimeIndex[i] && timeHourMinute <= allTimeIndex[i + 1]) {
                        index = i;
                        break;
                    }
                }
                //当前时间段 
                let myTime = allTimePhase[index];
                //获取医生排班列表
                this.getDoctorScheduleList(allTimePhase[index]);
                this.setState({
                    visible: true,
                    selectedDepartment: '',
                    selectedDoctor: '',
                    selectedTimePhase: '',
                    timePhaseValue: allTimePhase[index],
                    departmentValue: undefined,
                    doctorValue: undefined,
                });
                //获取科室列表，模态框筛选显示
                this.getDepartmentsList();
                //获得该用户的门店信息，模态框时间段筛选显示
                this.getStoreInfo(JSON.parse(sessionStorage.getItem('UserInfo')).shop[0]);
                //获得医生信息，模态框医生筛选显示
                this.getDoctorList()
            }
        })
    }
    //只是保存登记
    justSave(mes, isHavingRegisted) {
        console.log(mes);
        console.log(isHavingRegisted);
        let thisUserInfo = [];
        if (isHavingRegisted) {
            console.log(this.state.patientInfos);
            let discount = 1;
            this.state.patientInfos.data.map(item => {
                if (item._id === this.state.registedId) {
                    thisUserInfo = item;
                    return;
                }
            });
            console.log(thisUserInfo);
            this.setState({
                shouldPayed: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price:0
            });
            let url = allRouter.patientOrigin + '/order/save';
            $.ajax({
                url: url,
                type: "post",
                async: true,
                traditional: true,
                headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
                data: {
                    clinicname: this.state.storeInfo._id,//门店
                    department: this.state.thisDoctorInfo.department.id, //科室
                    doctor: this.state.thisDoctorInfo.id,//医生
                    consumptiontime: getFormatDate(new Date()) + ' ' + this.state.timePhaseValue.slice(6, 11),//  就诊时间
                    consumptionmoney: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price:0,//应收金额
                    payer: thisUserInfo._id,//付款人
                    paytype: 1,//支付类型
                    ordertype: '挂号费-' + this.state.thisDoctorInfo.department.name + (this.state.thisDoctorInfo.level?this.state.thisDoctorInfo.level:''),//订单类型
                    chargeschedule: JSON.stringify([{
                        p_name: '挂号费',//收费名称
                        p_Number: 1,//数量
                        p_price: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price.toFixed(2):0,//   单价
                        p_speci: '次',// 规格
                        p_money: this.state.thisDoctorInfo.price?(this.state.thisDoctorInfo.price * 1).toFixed(2):0,//  金额
                        p_discount: 1,// 折扣
                        p_dismoney: this.state.thisDoctorInfo.price?(this.state.thisDoctorInfo.price * 1 * 1).toFixed(2):0,// 折后金额
                        p_doctor: this.state.thisDoctorInfo.department.name + '-' + this.state.thisDoctorInfo.name,//  接诊医生
                        p_paystate: 2,//  单个服务支付状态
                        p_servedNumber: 0,//已服务次数
                        p_isReturn: 0,//标志是否退费  0：未退费  1：已退费
                    }]),//收费明细
                },
                success: res => {
                    console.log(res);
                    console.log(this.state.patientInfo._id);
                    browserHistory.push({ pathname: 'payConfirm', state: JSON.stringify({ name: thisUserInfo.username, patientId: thisUserInfo._id, myId: res.docs._id }) });
                },
                error: err => {
                    console.log(err);
                }
            }) 
            return;
        }
        this.props.form.validateFields((err, fieldsValue) => {
            console.log(err, fieldsValue);
            if (!err) {
                const values = {
                    ...fieldsValue,
                    'birthday': fieldsValue['birthday'].format('YYYY-MM-DD'),
                };
                // console.log(values);
                let familyData = [];
                familyData.push({ name: values.name1, relationship: values.relationship1, gender: values.gender1, birthday: values.birthday1 ? values.birthday1.format('YYYY-MM-DD') : undefined, phone: values.phone1 })
                values.keys.map(i => {
                    let v1 = 'name1' + i;
                    let v2 = 'relationship1' + i;
                    let v3 = 'gender1' + i;
                    let v4 = 'birthday1' + i;
                    let v5 = 'phone1' + i;
                    values[v1] = fieldsValue[v1];
                    values[v2] = fieldsValue[v2];
                    values[v3] = fieldsValue[v3];
                    values[v4] = fieldsValue[v4] ? fieldsValue[v4].format('YYYY-MM-DD') : undefined;
                    values[v5] = fieldsValue[v5];
                    familyData.push({ name: values[v1], relationship: values[v2], gender: values[v3], birthday: values[v4], phone: values[v5] })
                })
                console.log(familyData);
                let url = allRouter.patientOrigin + '/patient/save';
                let that = this;
                $.ajax({
                    url: url,
                    type: "post",
                    async: true,
                    traditional: true,
                    headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
                    data: {
                        username: values.name,//患者姓名
                        usersex: values.gender,//性别
                        userbirthday: values.birthday,//出生日期
                        userphone: values.phone,//手机号
                        userpapers: values.cardType,//证件类型
                        userIDcard: values.card,//证件号
                        userprovince: values.address ? values.address.join('/') : undefined,//家庭省市区地址
                        useraddress: values.addressDetail,//详细住址
                        userimg: values.Filedata ? values.Filedata[0].response ? values.Filedata[0].response.name : values.Filedata[0].name : '',//患者照片
                        membercardno: values.patientCardId,//患者卡号
                        usersource: values.patientOrigin,//用户来源
                        membertypes: values.userType,//会员类型
                        usermarriage: values.marryState,//婚姻状况
                        userproffession: values.job,//职业
                        userworkunit: values.jobAddress,//工作单位
                        usernation: values.nation,//民族
                        useremail: values.email,//邮件地址
                        familydata: JSON.stringify(familyData),//家庭信息
                        registerpeople: JSON.stringify({ id: JSON.parse(sessionStorage.getItem('UserInfo')).id, name: JSON.parse(sessionStorage.getItem('UserInfo')).name,receptiontype: 0, }),
                        // registrationmes: JSON.stringify([{ receptiontime: '', receptiontype: 0, section: { id: '', name: '' }, registerpeople: { id: userInfo.id, name: userInfo.name }, doctor: { id: '', name: '' }, registrationlv: '', registrationmoney: 0, paystate: 0 }]),//包含所有挂号信息
                        signmes: JSON.stringify([{ height: 0, weight: 0, pulse: 0, breathe: 0, bloodpressure: 0 }]),//体征信息
                    },
                    success: data => {
                        console.log(data);
                        if (data.code === 200) {
                            if (mes) {
                                message.info('患者信息增加成功');
                                this.changeTab(2);
                            } else {
                                that.setState({
                                    patientInfo: data.data,
                                }, () => {
                                    console.log('此为添加分诊信息，生成订单');
                                    console.log(this.state.patientInfo);
                                    console.log(this.state.patientInfo._id);
                                    //会员等级
                                        this.setState({
                                            shouldPayed: this.state.thisDoctorInfo.price
                                        });
                                        let url = allRouter.patientOrigin + '/order/save';
                                        $.ajax({
                                            url: url,
                                            type: "post",
                                            async: true,
                                            traditional: true,
                                            headers: { Authorization: 'Bearer ' + sessionStorage.getItem('token') },
                                            data: {
                                                clinicname: this.state.storeInfo._id,//门店
                                                department: this.state.thisDoctorInfo.department.id, //科室
                                                doctor: this.state.thisDoctorInfo.id,//医生
                                                consumptiontime: getFormatDate(new Date()) + ' ' + this.state.timePhaseValue.slice(6, 11),//  就诊时间
                                                consumptionmoney: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price:0,//应收金额
                                                payer: this.state.patientInfo._id,//付款人
                                                paytype: 1,//支付类型
                                                ordertype: '挂号费-' + this.state.thisDoctorInfo.department.name + (this.state.thisDoctorInfo.level?this.state.thisDoctorInfo.level:''),//订单类型
                                                chargeschedule: JSON.stringify([{
                                                    p_name: '挂号费',//收费名称
                                                    p_Number: 1,//数量
                                                    p_price: this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price.toFixed(2):0,//   单价
                                                    p_speci: '次',// 规格
                                                    p_money: this.state.thisDoctorInfo.price?(this.state.thisDoctorInfo.price * 1).toFixed(2):0,//  金额
                                                    p_discount: 1,// 折扣
                                                    p_dismoney: this.state.thisDoctorInfo.price?(this.state.thisDoctorInfo.price * 1 * 1).toFixed(2):0,// 折后金额
                                                    p_doctor: this.state.thisDoctorInfo.department.name + '-' + this.state.thisDoctorInfo.name,//  接诊医生
                                                    p_paystate: 2,//  单个服务支付状态
                                                    p_servedNumber: 0,//已服务次数
                                                    p_isReturn: 0,//标志是否退费  0：未退费  1：已退费
                                                }]),//收费明细
                                            },
                                            success: res => {
                                                console.log(res);
                                                console.log(this.state.patientInfo._id);
                                                if(res.code===200){
                                                    console.log(res.docs._id);
                                                    browserHistory.push({ pathname: 'payConfirm', state: JSON.stringify({ name: this.state.patientInfo.username, patientId: this.state.patientInfo._id, myId: res.docs._id }) });
                                                }else{
                                                    message.info('订单生成失败，请重新操作！',2);
                                                }
                                            },
                                            error: err => {
                                                console.log(err);
                                            }
                                        })
                                        // 此为添加分诊信息，生成订单

                                })
                            }
                        } else {
                            message.info('患者信息增加失败');
                        }
                    },
                    error: err => {
                        console.log(err);
                    }
                });
            }
        })
    }
    //分诊模态框点击确定，去到支付页面
    handleTriageConfirm(isHavingRegisted) {
        console.log(isHavingRegisted);                                
        this.justSave(false, isHavingRegisted);
    }
    //点击医生头像，显示医生详细挂号费信息
    medicalInformation(item) {
        this.setState({
            visible1: true,
        });
        console.log(item);
        this.setState({
            thisDoctorInfo: item,
        })
    }
    // 日期
    changeDate(date, str) {
        this.setState({
            date,
            data1: str,
        });
        this.getPatientInfo(1, str[0], str[1],this.state.Inkey);
    }
    //搜索关键字
    changeInkey(e) {
        this.setState({
            Inkey: e.target.value
        })
    }
    //搜索
    searchRoles(e) {
        let value = e.target.value || this.state.Inkey;
        console.log(value);
        this.getPatientInfo(1, this.state.data1[0], this.state.data1[1], value);
    }
    //分页
    changePage(pageindex) {
        this.setState({
            pageindex
        });
        this.getPatientInfo(pageindex, this.state.data1[0], this.state.data1[1], this.state.Inkey);
    }
    //安排分诊或者重新预约调用的函数
    handleScheduleOrAppointment(status, id) {
        //  1:待分诊  2:待接诊  3:接诊中  4.已完成
        console.log(status);
        console.log(id);
        if (status === 1 || status === 4) {
            this.setState({
                isHavingId: true,
                registedId: id,
            });
            //这是分诊
            const timeHourMinute = new Date().toTimeString().slice(0, 5);
            // console.log(timeHourMinute);
            let index = 0;
            for (let i = 0; i < allTimeIndex.length; i++) {
                if (timeHourMinute >= allTimeIndex[i] && timeHourMinute <= allTimeIndex[i + 1]) {
                    index = i;
                    break;
                }
            }
             //当前时间段
             let myTime = allTimePhase[index];
             //获取医生排班列表
             this.getDoctorScheduleList(allTimePhase[index]);
            this.setState({
                visible: true,
                selectedDepartment: '',
                selectedDoctor: '',
                selectedTimePhase: '',
                timePhaseValue: allTimePhase[index],
                departmentValue: undefined,
                doctorValue: undefined,
            });
            //获取科室列表，模态框筛选显示
            this.getDepartmentsList();
            //获得该用户的门店信息，模态框时间段筛选显示
            this.getStoreInfo(JSON.parse(sessionStorage.getItem('UserInfo')).shop[0]);
            //获得医生信息，模态框医生筛选显示
            this.getDoctorList()
        } else {
            //这是重新预约
            //重新预约规划到二期
            // this.setState({
            //     visible2: true
            // });
            // const timeHourMinute = new Date().toTimeString().slice(0, 5);
            // // console.log(timeHourMinute);
            // let index = 0;
            // for (let i = 0; i < allTimeIndex.length; i++) {
            //     if (timeHourMinute >= allTimeIndex[i] && timeHourMinute <= allTimeIndex[i + 1]) {
            //         index = i;
            //         break;
            //     }
            // }
            // this.setState({
            //     selectedDepartment: '',
            //     selectedDoctor: '',
            //     selectedTimePhase: '',
            //     timePhaseValue: allTimePhase[index],
            //     departmentValue: undefined,
            //     doctorValue: undefined,
            // });
            // //获取科室列表
            // this.getDepartmentsList();
            // //获得该用户的门店信息
            // this.getStoreInfo(JSON.parse(sessionStorage.getItem('UserInfo')).shop[0]);
        }
    }
    //重新预约模态框取消
    handleCancel2() {
        this.setState({
            visible2: false
        })
    }
    //重新预约模态框确定
    handleOk2() {
        this.setState({
            visible3: true
        })
    }
    //重新预约确认信息模态框取消
    handleCancel3() {
        this.setState({
            visible3: false
        })
    }
    //重新预约确认信息模态框确定
    handleOk3() {
        this.setState({
            visible3: false
        })
    }
    //是否选择了证件类型
    handleSelectIdCard(value){
        console.log(value);
        if(value){
            this.setState({
                isAlreadyChosedIdCard:true,
            })
        }
    }

    render() {
        const { getFieldDecorator, getFieldValue } = this.props.form;
        getFieldDecorator('keys', { initialValue: [] });
        const keys = getFieldValue('keys');
        const formItems = keys.map((k, index) => {
            // console.log(index);
            return (
                <Row key={index}>
                    <Col span={4}>
                        <FormItem label='姓名' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                            {getFieldDecorator('name1' + k, {
                                rules: [
                                    { max: 20, message: '最多不能超过20个字' },
                                    { pattern: /^([\u4e00-\u9fa5]|[a-zA-Z0-9])+$/, message: '请输入中文或英文或数字' }
                                ]
                            })(
                                <Input placeholder="请输入姓名" />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={4}>
                        <FormItem label='关系' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                            {getFieldDecorator('relationship1' + k, {
                                rules: [
                                    { max: 10, message: '最多不能超过10个字' },
                                    { pattern: /^([\u4e00-\u9fa5])+$/,message: '请输入中文' }
                                    ]
                            })(
                                <Input placeholder="请输入与患者的关系" />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={3}>
                        <FormItem label='性别' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                            {getFieldDecorator('gender1' + k, {
                            })(
                                <Select placeholder='请选择性别' style={{ width: '100%' }} >
                                    <Option value='男'>男</Option>
                                    <Option value='女'>女</Option>
                                    <Option value='不详'>不详</Option>
                                </Select>
                            )}
                        </FormItem>
                    </Col>
                    <Col span={4}>
                        <FormItem label='出生日期' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                            {getFieldDecorator('birthday1' + k, {
                            })(
                                <DatePicker allowClear placeholder='出生日期' disabledDate={(val) => this.disabledDate(val)} />
                            )}
                        </FormItem>
                    </Col>
                    <Col span={4}>
                        <FormItem label='手机号' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                            {getFieldDecorator('phone1' + k, {
                                rules: [{ pattern: /^(1[34578]\d{9})$/, message: '请输入正确的手机号' }]
                            })(
                                <Input placeholder="请输入11位手机号" />
                            )}
                        </FormItem>
                    </Col>
                    {keys.length > 0 ? (
                        <div style={{ display: 'inline-block', float: 'right', marginRight: '17%' }}>
                            <Button onClick={() => this.remove(k)} type="primary">
                                <Icon type="minus" />
                            </Button>
                        </div>
                    ) : null}
                </Row>
            );
        });
        return (
            <div className='container'>
                <div className='btnBox'>
                    {this.props.location.state ? '' : <Button type={this.state.tabKey === 1 ? 'primary' : ''} onClick={() => this.changeTab(1)}>新增患者</Button>}
                    <Button style={{marginLeft:'10px'}} type={this.state.tabKey === 2 ? 'primary' : ''} onClick={() => this.changeTab(2)}>登记记录</Button>
                    {this.state.tabKey === 1 ? '' : (this.props.location.state ? '' : <div className='role-manage-box-search my-clear-fix employee-manage-box-search'>
                        <div className='addetd-z employee-manage-search'>
                            <InputGroup >
                                <RangePicker style={{ width: '600px' }}
                                    placeholder={['请选择日期', '请选择日期']}
                                    onChange={this.changeDate.bind(this)}
                                    format='YYYY-MM-DD'
                                    value={this.state.date}
                                />
                                <Input
                                    placeholder="请输入患者姓名或手机号"
                                    value={this.state.Inkey}
                                    onChange={(e) => this.changeInkey(e)}
                                    onPressEnter={(e) => this.searchRoles(e)}
                                />
                            </InputGroup>
                        </div>
                        <div className="role-manage-right">
                            <Button type="primary" className='member-button' icon="search" onClick={this.searchRoles.bind(this)} >搜索</Button>
                        </div>
                    </div>)}
                </div>
                {
                    this.state.tabKey === 1 ?
                        <div className='addpatient'>
                            <div>
                                <h3 className='title'>基本信息</h3>
                                <Row>
                                    <Col span={6}>
                                        <FormItem label='患者姓名' labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
                                            {getFieldDecorator('name', {
                                                rules: [{ required: true, message: '请输入患者姓名' },
                                                { max: 20, message: '最多不能超过20个字' },
                                                { pattern: /^([\u4e00-\u9fa5]|[a-zA-Z0-9])+$/, message: '请输入中文或英文或数字' }
                                                ],
                                            })(
                                                <Input placeholder="请输入患者姓名" />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={4}>
                                        <FormItem label='性别' labelCol={{ span: 9 }} wrapperCol={{ span: 14 }}>
                                            {getFieldDecorator('gender', {
                                                rules: [{ required: true, message: '请选择性别' }],
                                            })(
                                                <Select style={{ width: '100%' }} placeholder="请选择性别">
                                                    <Option value='男'>男</Option>
                                                    <Option value='女'>女</Option>
                                                    <Option value='不详'>不详</Option>
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={4}>
                                        <FormItem label='出生日期' labelCol={{ span: 9 }} wrapperCol={{ span: 14 }}>
                                            {getFieldDecorator('birthday', {
                                                rules: [{ required: true, message: '请选择出生日期' }],
                                            })(
                                                <DatePicker allowClear placeholder='出生日期' disabledDate={(val) => this.disabledDate(val)} onChange={this.calculateAge.bind(this)} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={1}><p style={{ marginTop: '10px' }}>({this.state.age}岁)</p></Col>
                                    <Col span={6} style={{ position: 'relative' }}>
                                        <FormItem labelCol={{ span: 10 }} wrapperCol={{ span: 14 }} style={{ minHeight: '120px', position: 'absolute', left: '40px', top: '40px' }}>
                                            {getFieldDecorator('Filedata', {
                                                valuePropName: 'fileList', getValueFromEvent: this.normFile.bind(this),
                                            })(
                                                <Upload
                                                    accept="image/*"
                                                    name="Filedata"
                                                    action={allRouter.UploadFile + "/uploadpageimg"}
                                                    beforeUpload={this.beforeUpload.bind(this)}
                                                    listType="picture-card"
                                                    className="upload-list-inline"
                                                    onPreview={this.previewImg.bind(this)}
                                                >
                                                    {
                                                        this.state.fileList.length >= 1 ? null :
                                                            <div >
                                                                <Icon type="plus" />
                                                                <div className="ant-upload-text">点击上传照片</div>
                                                            </div>
                                                    }
                                                </Upload>
                                            )}
                                        </FormItem>
                                        {/* 预览图片对话框 */}
                                        <Modal visible={this.state.previewVisible} footer={null} onCancel={this.cancelPreview.bind(this)}>
                                            <img alt="example" style={{ width: '100%' }} src={this.state.previewImage} />
                                        </Modal>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={6}>
                                        <FormItem label='手机号' labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
                                            {getFieldDecorator('phone', {
                                                rules: [{ pattern: /^(1[34578]\d{9})$/, message: '请输入正确的手机号' }]
                                            })(
                                                <Input placeholder="请输入11位手机号" />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={4}>
                                        <FormItem label='证件类型' labelCol={{ span: 9 }} wrapperCol={{ span: 14 }}>
                                            {getFieldDecorator('cardType', {
                                            })(
                                                <Select placeholder='请选择证件类型' style={{ width: '100%' }} onChange={this.handleSelectIdCard.bind(this)}>
                                                    <Option value='二代身份证'>二代身份证</Option>
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={4}>
                                        <FormItem>
                                            {getFieldDecorator('card', {
                                                rules: [{ pattern: /^[1-9]\d{5}[1-9]\d{3}((0\d)|(1[0-2]))(([0|1|2]\d)|3[0-1])\d{3}([0-9]|X|x)$/, message: '请输入18位身份证号' }]
                                            })(<Input disabled={this.state.isAlreadyChosedIdCard?false:true} placeholder=" 输入18位二代身份证号码" />)}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={6}>
                                        <FormItem labelCol={{ span: 8 }} wrapperCol={{ span: 16 }} label="家庭住址" >
                                            {getFieldDecorator('address', {
                                                rules: [{ type: 'array', message: '请选择家庭住址所在的地区！' }],
                                            })(
                                                <Cascader options={region} placeholder="请选择省市区" style={{ width: '100%' }} />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={8}>
                                        <FormItem>
                                            {getFieldDecorator('addressDetail', {
                                                rules: [
                                                    { max: 200, message: '最多不能超过200个字符' },
                                                    { pattern: /^\S+$/, message: '请不要输入空格'}
                                                ]
                                            })(<Input placeholder="请输入详细地址" />)}
                                        </FormItem>
                                    </Col>
                                </Row>
                            </div>
                            <div>
                                <h3 className='title'>更多信息</h3>
                                <Row>
                                    <Col span={6}>
                                        <FormItem label='患者卡号' labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
                                            {getFieldDecorator('patientCardId', {
                                                rules: [
                                                    { max: 20, message: '最多不能超过20个字符' },
                                                    { pattern: /^([a-zA-Z0-9])+$/, message: '请输入英文或数字' }
                                                ]
                                            })(
                                                <Input placeholder="请输入ID" />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={4}>
                                        <FormItem label='患者来源' labelCol={{ span: 9 }} wrapperCol={{ span: 14 }}>
                                            {getFieldDecorator('patientOrigin', {
                                            })(
                                                <Select placeholder='请选择患者来源' style={{ width: '100%' }} >
                                                    {this.state.patientOriginList.map(item => {
                                                        return <Option value={item._id} key={item._id}>{item.name}</Option>
                                                    })}
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={4}>
                                        <FormItem label='会员类型' labelCol={{ span: 9 }} wrapperCol={{ span: 14 }}>
                                            {getFieldDecorator('userType', {
                                            })(
                                                <Select placeholder='请选择会员类型' style={{ width: '100%' }} >
                                                    {this.state.userTypeManageList.map(item => {
                                                        return <Option value={item._id} key={item._id}>{item.name}</Option>
                                                    })}
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={6}>
                                        <FormItem label='婚姻状况' labelCol={{ span: 8 }} wrapperCol={{ span: 16 }}>
                                            {getFieldDecorator('marryState', {
                                            })(
                                                <Select placeholder='请选择' style={{ width: '100%' }} >
                                                    <Option value='已婚'>已婚</Option>
                                                    <Option value='未婚'>未婚</Option>
                                                    <Option value='丧偶'>丧偶</Option>
                                                    <Option value='离异'>离异</Option>
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={4}>
                                        <FormItem label='职业' labelCol={{ span: 9 }} wrapperCol={{ span: 14 }}>
                                            {getFieldDecorator('job', {
                                                rules: [
                                                    { max: 20, message: '最多不能超过20个字符' },
                                                    { pattern: /^([\u4e00-\u9fa5]|[a-zA-Z])+$/, message: '请输入中文或英文' }]
                                            })(
                                                <Input placeholder="请输入职业" />
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={4}>
                                        <FormItem label='工作地址' labelCol={{ span: 9 }} wrapperCol={{ span: 14 }}>
                                            {getFieldDecorator('jobAddress', {
                                                rules: [
                                                    { max: 200, message: '最多不能超过200个字符' },
                                                    { pattern: /^\S+$/, message: '请不要输入空格'}
                                                ]
                                            })(
                                                <Input placeholder="请填写工作地址" />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                                <Row>
                                    <Col span={6}>
                                        <FormItem {...{ labelCol: { span: 8 }, wrapperCol: { span: 16 } }} label="名族" >
                                            {getFieldDecorator('nation', {

                                            })(
                                                <Select style={{ width: '100%' }} placeholder="请选择">
                                                    {nations.map(item => {
                                                        return <Option key={item.id} value={item.name}>{item.name}</Option>
                                                    })}
                                                </Select>
                                            )}
                                        </FormItem>
                                    </Col>
                                    <Col span={8}>
                                        <FormItem {...{ labelCol: { span: 5 }, wrapperCol: { span: 12 } }} label="负责人邮箱" >
                                            {getFieldDecorator('email', {
                                                rules: [{
                                                    type: 'email', message: '请输入正确格式邮箱',
                                                }],
                                            })(
                                                <Input />
                                            )}
                                        </FormItem>
                                    </Col>
                                </Row>
                            </div>
                            <div>
                                <h3 className='title'>家庭成员</h3>
                                <div>
                                    <Row>
                                        <Col span={4}>
                                            <FormItem label='姓名' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                                                {getFieldDecorator('name1', {
                                                    rules: [
                                                        { max: 20, message: '最多不能超过20个字' },
                                                        { pattern: /^([\u4e00-\u9fa5]|[a-zA-Z0-9])+$/, message: '请输入中文或英文或数字' }
                                                    ]
                                                })(
                                                    <Input placeholder="请输入姓名" />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={4}>
                                            <FormItem label='关系' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                                                {getFieldDecorator('relationship1', {
                                                    rules: [
                                                        { max: 10, message: '最多不能超过10个字' },
                                                        { pattern: /^([\u4e00-\u9fa5])+$/,message: '请输入中文' }
                                                        ]
                                                })(
                                                    <Input placeholder="请输入与患者的关系" />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={3}>
                                            <FormItem label='性别' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                                                {getFieldDecorator('gender1', {
                                                })(
                                                    <Select placeholder='请选择性别' style={{ width: '100%' }} >
                                                        <Option value='男'>男</Option>
                                                        <Option value='女'>女</Option>
                                                        <Option value='不详'>不详</Option>
                                                    </Select>
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={4}>
                                            <FormItem label='出生日期' labelCol={{ span: 7 }} wrapperCol={{ span: 14 }}>
                                                {getFieldDecorator('birthday1', {
                                                })(
                                                    <DatePicker allowClear placeholder='出生日期' disabledDate={(val) => this.disabledDate(val)} />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <Col span={4}>
                                            <FormItem label='手机号' labelCol={{ span: 6 }} wrapperCol={{ span: 14 }}>
                                                {getFieldDecorator('phone1', {
                                                    rules: [{ pattern: /^(1[34578]\d{9})$/, message: '请输入正确的手机号' }]
                                                })(
                                                    <Input placeholder="请输入11位手机号" />
                                                )}
                                            </FormItem>
                                        </Col>
                                        <div style={{ display: 'inline-block', float: 'right', marginRight: '17%' }}>
                                            <Button onClick={this.add.bind(this)} type="primary">
                                                <Icon type="plus" />
                                            </Button>
                                        </div>
                                    </Row>
                                </div>
                                {formItems}
                            </div>


                            <div className='saveBtn'>
                                <Button onClick={this.saveAndTriage.bind(this)} type="primary">完成登记并分诊</Button>
                                <Button onClick={this.justSave.bind(this, true, false)}>保存登记</Button>
                            </div>
                        </div>
                        :
                        <div className='addpatient'>
                            <div style={{ background: '#ECECEC', padding: '30px' }}>
                                <Row gutter={16}>
                                    {this.state.patientInfos.data.length ? this.state.patientInfos.data.map(item => {
                                        return <Col span={8} key={item._id} style={{ marginBottom: '20px' }}>
                                            <Card bordered={false}>
                                                <img src={require('../../../images/patientDefault.png')} className="default-img"/>
                                                <div className="fsecd">
                                                    <h6><b style={{ fontSize: '20px', color: '#1890ff' }}>{item.username}</b>( {item.usersex + ' ' + (new Date().getFullYear() - item.userbirthday.slice(0, 4)) + '岁'} )</h6>
                                                    <p>接诊类型：{item.Receptionmes?item.Receptionmes.receptiontype===0?'初诊':'复诊':''}</p>
                                                    <p>登记科室：{item.registrationmes?item.registrationmes.department.department_name:''}</p>
                                                    <p>接诊医生：{item.registrationmes?item.registrationmes.doctor.doctor_name:''}</p>
                                                    <p>登记人员：{item.Receptionmes?item.Receptionmes.name:''}</p>
                                                    <p>会员等级：{this.state.userTypeManageList.map(key => {
                                                        if (key._id === item.membertypes) {
                                                            return key.name;
                                                        }
                                                    })}</p>
                                                    <p>登记时间：{item.createtime}</p>
                                                </div>
                                                <span  className='triageType' size="small" style={{background:item.status===1?'#888':item.status===2?'#999':item.status === 3?'#bbb':'#fff' }}>{item.status===1?'待分诊':item.status===2?'待接诊':item.status === 3?'接诊中':''}</span>
                                           </Card>
                                            <div className="hdsf">
                                                <Button type="primary" onClick={() => { browserHistory.push('patientInfoDetails/' + item._id) }}>完善资料</Button>
                                                <Button type="primary" onClick={this.handleScheduleOrAppointment.bind(this, item.status, item._id)} >{item.status === 1 || item.status === 4 ? "安排分诊" : '重新预约'}</Button>
                                            </div>
                                        </Col>
                                    }) : ''}
                                </Row>
                            </div>
                            {/*分页*/}
                            <div className="pagination">
                                <Pagination showQuickJumper current={this.state.pageindex} total={this.state.patientInfos.counts || 1} defaultPageSize={this.state.pagesize} onChange={this.changePage.bind(this)} />
                            </div>
                        </div>
                }
                {/*选择医生模态框*/}
                <Modal
                    title="选择医生"
                    className="large-model"
                    visible={this.state.visible}
                    onCancel={
                        () => {
                            this.setState({ visible: false });
                            this.setState({
                                isHavingId: false,
                            })
                        }}
                    footer={null}
                >
                    <div className='xzys'>
                        <Select style={{ width: 150 }} placeholder="请选择时间段" onChange={this.handleChangeTimePhase.bind(this)} value={this.state.timePhaseValue}>
                            {this.state.allTimePhase.length ? this.state.allTimePhase.map((item, index) =>
                                <Option value={item} key={index}>{item}</Option>
                            ) :
                                ""}
                        </Select>
                        <Select style={{ width: 150 }} placeholder="请选择科室" onChange={this.handleChangeDepartment.bind(this)} value={this.state.departmentValue}>
                            <Option value='' >请选择</Option>
                            {this.state.departmentsList.map(item => {
                                return <Option value={item._id} key={item._id}>{item.name}</Option>
                            })}
                        </Select>
                        <Select style={{ width: 150 }} placeholder="请选择医生" onChange={this.handleChangeDoctor.bind(this)} value={this.state.doctorValue}>
                            <Option value='' >请选择</Option>
                            {this.state.everyDoctorList.length ? this.state.everyDoctorList.map((item, index) => {
                                return <Option value={item._id} key={index}>{item.name}</Option>
                            }) : ''}
                        </Select>
                    </div>
                    <div className="xzys1">
                        {this.state.registrationFeeList.map(item => {
                            return (<a href="javascript:void(0);" key={item._id} onClick={this.medicalInformation.bind(this, item)}>
                                <Col span={3}>
                                    <Card bordered={false}>
                                        <img src={require('../../../images/doctorDeafult.png')} className="default-img"/>
                                        <div className="fsecd">
                                            <h6 style={{ marginBottom: '0px' }}>{item.name}</h6>
                                            <h6>({item.department ? item.department.name : ''})</h6>
                                            <p>待接诊：{item.totreat?item.totreat:0}人</p>
                                            <p>已接诊：{item.alreadyaccepts?item.alreadyaccepts:0}人</p>
                                        </div>
                                    </Card>
                                </Col>
                            </a>)
                        })}
                    </div>
                </Modal>
                {/*点击医生头像显示医生挂号费详细信息*/}
                <Modal title="就诊信息确认" visible={this.state.visible1} className="medicalInformation"
                    onCancel={() => {
                        this.setState({ visible1: false });
                    }}
                    onOk={this.handleTriageConfirm.bind(this, this.state.isHavingId)}
                >
                    <p>就诊科室：{this.state.thisDoctorInfo.department ? this.state.thisDoctorInfo.department.name : ''}</p>
                    <p>就诊医生：{this.state.thisDoctorInfo.name} {this.state.thisDoctorInfo.level}</p>
                    <p>就诊时间：{new Date().toLocaleDateString()} {this.state.timePhaseValue.slice(6, 11)}</p>
                    <p><b>挂号费：￥{this.state.thisDoctorInfo.price?this.state.thisDoctorInfo.price:0}</b></p>
                </Modal>

                {/*重新预约信息*/}
                <Modal title="重新预约" visible={this.state.visible2}
                    onOk={this.handleOk2.bind(this)}
                    onCancel={this.handleCancel2.bind(this)}
                >
                    <div className='xzys xzys2'>
                        <span>选择时间：</span>
                        <DatePicker />

                        <Select style={{ width: 150 }} placeholder="请选择时间段" onChange={this.handleChangeTimePhase.bind(this)} value={this.state.timePhaseValue}>
                            {this.state.allTimePhase.length ? this.state.allTimePhase.map((item, index) =>
                                <Option value={item} key={index}>{item}</Option>
                            ) :
                                ""}
                        </Select>
                    </div>
                    <div className='xzys xzys2'>
                        <span>选择科室：</span>
                        <Select style={{ width: 150 }} placeholder="请选择科室" onChange={this.handleChangeDepartment.bind(this)} value={this.state.departmentValue}>
                            {this.state.departmentsList.map(item => {
                                return <Option value={item._id} key={item._id}>{item.name}</Option>
                            })}
                        </Select>
                    </div>
                    <div className='xzys xzys2'>
                        <span>选择医生：</span>
                        <Select style={{ width: 150 }} placeholder="请选择医生" onChange={this.handleChangeDoctor.bind(this)} value={this.state.doctorValue}>
                            {this.state.everyDoctorList.length ? this.state.everyDoctorList.map((item, index) => {
                                return <Option value={item._id} key={index}>{item.name}</Option>
                            }) : ''}
                        </Select>
                    </div>
                </Modal>
                {/*重新预约信息确认*/}
                <Modal title="就诊信息确认" visible={this.state.visible3}
                    onOk={this.handleOk3.bind(this)}
                    onCancel={this.handleCancel3.bind(this)}


                >
                    <div>
                        <Row>
                            <Col span={12}>
                                <p>原就诊科室：内科</p>
                                <p>原就诊医生：张医生</p>
                                <p>原就诊时间：2018-01-01 08:00</p>
                                <p><b>原挂号费：￥ 30.00</b></p>
                            </Col>
                            <Col span={12}>
                                <p>现就诊科室：外科</p>
                                <p>现就诊医生：李医生</p>
                                <p>现就诊时间：2018-01-02 08:00</p>
                                <p><b>现挂号费：￥50.00</b></p>
                            </Col>
                        </Row>
                    </div>

                </Modal>
            </div>
        )
    }
}
const LoginTriageForm = Form.create()(LoginTriage);
export default LoginTriageForm